#include <tws_debugging.h>
#include <xwritelogexport.h>
#include "xdatabootconf.h"

static const char k_boot_conf[]				= "/usr/infomat/boot.conf";
static const char k_ini_sec[]				= "";
static const char k_ini_key_volume[]		= "volume";
static const char k_ini_key_lcdUpDown[]		= "LCD_Up/Down";
static const char k_ini_key_lcdLeftRight[]	= "LCD_Left/Right";
static const char k_ini_key_bootLayout[]	= "Boot_Layout";
static const char k_ini_key_bootPlu[]		= "Boot_PLU";
static const char k_ini_key_font[]			= "Font";
static const char k_ini_key_fontSize[]		= "FontSize";
static const char k_ini_key_wmFont[]		= "WMFont";
static const char k_ini_key_wmFontSize[]	= "WMFontSize";
static const char k_ini_key_qfont[]			= "QFont";
static const char k_ini_key_qfontSize[]		= "QFontSize";
static const char k_ini_key_timeout[]		= "Timeout";
static const char k_ini_key_nameFont[]		= "NameFont";
static const char k_ini_key_nameFontSize[]	= "NameFontSize";
static const char k_ini_key_screenMode[]    = "ScreenMode";      //enable Screen Mode (0-off,1-on)
static const char k_ini_key_discountFontFamily[]="DiscountFontFamily";
static const char k_ini_key_discountStartX[] = "DiscountStartX";
static const char k_ini_key_discountStartY[] = "DiscountStartY";
static const char k_ini_key_discountWidth[] = "DiscountWidth";
static const char k_ini_key_discountHeigh[] = "DiscountHeigh";
static const char k_ini_key_discountFontSize[] = "DiscountFontSize";

XDataBootConf::XDataBootConf()
{
	this->clearStBootConf();
	m_inifile.open(k_boot_conf);
	char tmp[32] = {0};
	m_inifile.readInt (k_ini_sec, k_ini_key_volume,			m_bootConf.volume);
	m_inifile.readInt (k_ini_sec, k_ini_key_lcdUpDown,		m_bootConf.lcdUpDown);
	m_inifile.readInt (k_ini_sec, k_ini_key_lcdLeftRight,	m_bootConf.lcdLeftRight);
	m_inifile.readInt (k_ini_sec, k_ini_key_bootLayout,		m_bootConf.layout);
	m_inifile.readInt (k_ini_sec, k_ini_key_bootPlu,		m_bootConf.plu);
	m_inifile.readInt (k_ini_sec, k_ini_key_fontSize,		m_bootConf.fontSize);
	m_inifile.readInt (k_ini_sec, k_ini_key_wmFontSize,		m_bootConf.wmFontSize);
	m_inifile.readInt (k_ini_sec, k_ini_key_qfontSize,		m_bootConf.qFontSize);
	m_inifile.readInt (k_ini_sec, k_ini_key_nameFontSize,	m_bootConf.nameFontSize);
	m_inifile.readInt (k_ini_sec, k_ini_key_timeout,		m_bootConf.timeout);
	m_inifile.readInt (k_ini_sec, k_ini_key_screenMode,     m_bootConf.screenMode);
	m_inifile.readInt (k_ini_sec, k_ini_key_discountStartX, m_bootConf.discountStartX);
	m_inifile.readInt (k_ini_sec, k_ini_key_discountStartY, m_bootConf.discountStartY);
	m_inifile.readInt (k_ini_sec, k_ini_key_discountWidth, m_bootConf.discountWidth);
	m_inifile.readInt (k_ini_sec, k_ini_key_discountHeigh, m_bootConf.discountHeigh);
	m_inifile.readInt (k_ini_sec, k_ini_key_discountFontSize, m_bootConf.discountFontSize);

	if (0!=m_bootConf.screenMode && 1!=m_bootConf.screenMode) {
		LOG_E("screen mode error");
		m_bootConf.screenMode = 0;   //default value
	}

	m_inifile.readString (k_ini_sec, k_ini_key_font,		tmp , 32);
	m_bootConf.font = tmp;
	memset (tmp, 0x00, 32);
	
	m_inifile.readString (k_ini_sec, k_ini_key_wmFont,		tmp,  32);
	m_bootConf.wmFont = std::string(tmp);
	memset (tmp, 0x00, 32);
	
	m_inifile.readString (k_ini_sec, k_ini_key_qfont,		tmp,  32);
	m_bootConf.qFont = std::string(tmp);
	memset (tmp, 0x00, 32);

	m_inifile.readString (k_ini_sec, k_ini_key_nameFont,   tmp,  32);
	m_bootConf.nameFont = std::string(tmp);
	memset (tmp, 0x00, 32);
	
	m_inifile.readString (k_ini_sec, k_ini_key_discountFontFamily,tmp , 32);
	m_bootConf.discountFontFamily = tmp;

	m_inifile.close();
//	this->DebugOutput();
}

XDataBootConf::~XDataBootConf()
{
}

/* *****************************************************************
 * [+] public function
 * *****************************************************************/
int XDataBootConf::getLayout() const { return m_bootConf.layout; }

int XDataBootConf::getWmFontSize() const { return m_bootConf.wmFontSize; }

int XDataBootConf::getTimeout() const { return m_bootConf.timeout; }

int XDataBootConf::screenMode() const {	
	return m_bootConf.screenMode; 
}

const STBootConf& XDataBootConf::getBootConf() const { return m_bootConf; }


/* *****************************************************************
 * [#] for debug output, output boot.conf content
 * ******************************************************************/
void XDataBootConf::DebugOutput ()   
{
	LOG_T("volume\t:%02d",		m_bootConf.volume);
	LOG_T("up down\t:%02d",		m_bootConf.lcdUpDown);
	LOG_T("left right\t:%02d",  m_bootConf.lcdLeftRight);
	LOG_T("layout:\t:%02d",		m_bootConf.layout);
	LOG_T("plu:\t:%02d",		m_bootConf.plu);
	LOG_T("font:\t:%s",			m_bootConf.font.c_str());
	LOG_T("font size:\t:%02d",  m_bootConf.fontSize);
	LOG_T("WMFont\t:%s",		m_bootConf.wmFont.c_str());
	LOG_T("WMFont Size\t:%02d",	m_bootConf.wmFontSize);
	LOG_T("QFont\t:%s",			m_bootConf.qFont.c_str());
	LOG_T("QFontSize\t:%02d",	m_bootConf.qFontSize);
	LOG_T("Name Font\t:%s",     m_bootConf.nameFont.c_str());
	LOG_T("Name Font Size:%02d", m_bootConf.nameFontSize);
	LOG_T("timeout\t:%02d",		m_bootConf.timeout);
	LOG_T("Screen Mode\t:%02d,0-off,1-on", m_bootConf.screenMode);
	LOG_T("discountFontFamily:\t:%s",m_bootConf.discountFontFamily.c_str());
	LOG_T("discount X\t:%02d",		m_bootConf.discountStartX);
	LOG_T("discount Y\t:%02d",		m_bootConf.discountStartY);
	LOG_T("discount Width\t:%02d",	m_bootConf.discountWidth);
	LOG_T("discount Heigh\t:%02d",	m_bootConf.discountHeigh);
	LOG_T("discount Font Size\t:%02d",	m_bootConf.discountFontSize);
}

/* ******************************************************************
 * [#] empty the struct
 * ******************************************************************/
void XDataBootConf::clearStBootConf()   
{
	m_bootConf.volume		= 0;
	m_bootConf.lcdUpDown	= 0;
	m_bootConf.lcdLeftRight = 0;
	m_bootConf.layout		= 0;
	m_bootConf.plu			= 0;
	m_bootConf.font.clear();
	m_bootConf.fontSize		= 0;
	m_bootConf.wmFont.clear();
	m_bootConf.wmFontSize	= 0;
	m_bootConf.qFont.clear();
	m_bootConf.qFontSize	= 0;
	m_bootConf.nameFont.clear();
	m_bootConf.nameFontSize = 0;
	m_bootConf.timeout		= 0;
	m_bootConf.screenMode 	= 0;   // 0-off, 1-open
	m_bootConf.discountFontFamily.clear();
	m_bootConf.discountStartX = 0;
	m_bootConf.discountStartY = 0;
	m_bootConf.discountWidth = 0;
	m_bootConf.discountHeigh = 0;
	m_bootConf.discountFontSize = 0;
	return;
}
